package cn.sh.yhk.task;

import cn.sh.yhk.model.basic.STaskScheduleJob;
import cn.sh.yhk.service.basic.JobConfigService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Auther: adminyhk
 * @Date: 2018/9/21 14:37
 * @Description:
 */
public class MyJob implements Job {

    @Resource
    private JobConfigService jobConfigService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        //是哪个定时任务配置在执行，可以看到，因为在前面我们将描述设置为了配置类的toString结果
        System.out.println(jobExecutionContext.getJobDetail().getDescription());
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(this.toString() + ":" + f.format(new Date()) +
                "正在执行Job executing...");
        List<STaskScheduleJob> configs = jobConfigService.getAllByStatus(1);
        for (STaskScheduleJob config : configs) {
            System.out.println(config.toString());
        }

    }
}
